package com.smrs.deliver.webapp.action;

import com.smrs.deliver.model.DeliverHeaderModel;




public class DeliverDetailJsonAction extends DeliverDetailAction{
	private static final long serialVersionUID = 1L;
	private Long id;
	private Double actualQuantify;
	private Double actualAmount;
	private Double actualPurchasePrice;
	

	
	public Long getId() {
		return id;
	}
	public void setId(Long id) {
		this.id = id;
	}
	public Double getActualQuantify() {
		return actualQuantify;
	}
	public void setActualQuantify(Double actualQuantify) {
		this.actualQuantify = actualQuantify;
	}
	public Double getActualAmount() {
		return actualAmount;
	}
	public void setActualAmount(Double actualAmount) {
		this.actualAmount = actualAmount;
	}
	public Double getActualPurchasePrice() {
		return actualPurchasePrice;
	}
	public void setActualPurchasePrice(Double actualPurchasePrice) {
		this.actualPurchasePrice = actualPurchasePrice;
	}
	
	public String updateDeliverDetailJson(){
		deliverDetail = deliverDetailService.getByPK(id);
		if(actualQuantify!=null && actualQuantify.doubleValue()>0d){
			deliverDetail.setActualQuantify(actualQuantify);
			deliverDetail.setActualAmount(actualQuantify*deliverDetail.getActualPurchasePrice());
		}
		if(actualPurchasePrice!=null && actualPurchasePrice.doubleValue()>0d){
			deliverDetail.setActualPurchasePrice(actualPurchasePrice);
			deliverDetail.setActualAmount(actualPurchasePrice* deliverDetail.getActualQuantify());
		}
		
		deliverDetailService.updateModel(deliverDetail);
		DeliverHeaderModel header = new DeliverHeaderModel();
		header.setId(deliverDetail.getDeliverId());
		deliverHeaderService.updateCalculateDeliverHeaderQuantifyAndAmount(header);
		return SUCCESS;
	}
	

}
